package com.masu.knows.auth;

import com.masu.knows.auth.filter.CorsFilter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.core.Ordered;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@EnableDiscoveryClient
public class KnowsAuthApplication {

	public static void main(String[] args) {
		SpringApplication.run(KnowsAuthApplication.class, args);
	}

	@Bean
	@LoadBalanced
	public RestTemplate restTemplate(){
		return new RestTemplate();
	}

	@Bean
	public FilterRegistrationBean registrationBean(){
		FilterRegistrationBean<CorsFilter> bean= new FilterRegistrationBean<>();
		// 设置哪些路径要经过滤器的处理
		bean.addUrlPatterns("/*");// 所有路径都需要过滤
		bean.setOrder(Ordered.HIGHEST_PRECEDENCE);// 设置优先级最高
		bean.setFilter(new CorsFilter());// 设置过滤器对象
		return bean;//返回设置到Spring容器
	}

}
